package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.StrategyDetailSign;
import cn.wolfcode.trip.base.mapper.StrategyDetailSignMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IStrategyDetailSignService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class StrategyDetailSignServiceImpl implements IStrategyDetailSignService {
    @Autowired
    private StrategyDetailSignMapper strategyDetailSignMapper;


    @Override
    public StrategyDetailSign get(Long id) {
        return strategyDetailSignMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<StrategyDetailSign> listAll() {
        return strategyDetailSignMapper.selectAll();
    }

    @Override
    public void save(StrategyDetailSign strategyDetailSign) {
        //设置点赞或者收藏的时间
        if (strategyDetailSign.getGreatStatus() != null) {
            strategyDetailSign.setGreatTime(new Date());
        }
        if (strategyDetailSign.getEnshrineStatus() != null) {
            strategyDetailSign.setEnshrineTime(new Date());
        }
        strategyDetailSignMapper.insert(strategyDetailSign);
    }

    @Override
    public void update(StrategyDetailSign strategyDetailSign) {
        //设置点赞或者收藏的时间
        if (strategyDetailSign.getGreatStatus() != null) {
            strategyDetailSign.setGreatTime(new Date());
        }
        if (strategyDetailSign.getEnshrineStatus() != null) {
            strategyDetailSign.setEnshrineTime(new Date());
        }
        strategyDetailSignMapper.updateByPrimaryKey(strategyDetailSign);

    }


    @Override
    public PageInfo queryForList(QueryObject qo) {
        return null;
    }

    @Override
    public void updateState(StrategyDetailSign strategyDetailSign) {

    }


    /**
     * 根据大攻略id查询当前用户的在该攻略下的标记状态
     *
     * @param strategyDetailId
     * @return
     */
    @Override
    public StrategyDetailSign selectByStrategyDetailId(Long strategyDetailId, Long userId) {

        return strategyDetailSignMapper.selectByStrategyDetailId(strategyDetailId, userId);
    }

    @Override
    public int queryGreatStatusCountByStrategyDetailId(Long strategyDetailId) {

        return strategyDetailSignMapper.queryGreatStatusCountByStrategyDetailId(strategyDetailId);
    }

    @Override
    public int queryEnshrineStatusCountByStrategyDetailId(Long strategyDetailId) {
        return strategyDetailSignMapper.queryEnshrineStatusCountByStrategyDetailId(strategyDetailId);
    }


}
